﻿@using Jx.Toolbox.Extensions
@using JxAudio.TransVo
@using Microsoft.Extensions.Localization
@implements IResultDialog
@inject IStringLocalizer<TrackSearch> StringLocalizer
@inject HttpClient Http

<div class="row g-3">
    <div class="col-12">
        <BootstrapInputGroup>
            <BootstrapInput @bind-Value="SearchText" PlaceHolder="@StringLocalizer["SearchText"]"></BootstrapInput>
            <Button Icon="fa fa-search" OnClick="Search"></Button>
        </BootstrapInputGroup>
    </div>
    <div class="col-12">
        <TrackTable Tracks="TrackVos" SelectedRows="SelectedTracks" ShowDefaultToolbar="false" ShowDefaultButton="false"
                    IsKeepSelectedRows="true"></TrackTable>
    </div>
</div>

@code {
    private string? SearchText { get; set; }
    
    public List<TrackVo>? TrackVos { get; set; }

    [Parameter]
    public List<TrackVo> SelectedTracks { get; set; } = new List<TrackVo>();

    private async Task Search()
    {
        if (SearchText.IsNullOrEmpty())
        {
            return;
        }
        var response = await Http.GetAsync("api/Track/Search?SearchText=" + SearchText);
        TrackVos = await response.Content.ReadFromJsonAsync<List<TrackVo>>();
    }

    public Task OnClose(DialogResult result)
    {
        return Task.CompletedTask;
    }

}